#include "device_gpio.h"

int device_gpio_key_init(gpio_num_t gpio_num, gpio_mode_t mode)
{
    gpio_config_t io_conf;
    io_conf.intr_type = GPIO_INTR_DISABLE;
    io_conf.mode = mode;
    io_conf.pin_bit_mask = BIT64(gpio_num);
    io_conf.pull_down_en = 0; 
    io_conf.pull_up_en = 1; //初始化上拉输入

    return gpio_config(&io_conf);
}


int device_gpio_get(gpio_num_t gpio_num)
{
    return gpio_get_level(gpio_num);
}

int device_gpio_init(gpio_num_t gpio_num, gpio_mode_t mode,EM_INPUT_TYPE pullType)
{
    gpio_config_t io_conf;
    //disable interrupt
    io_conf.intr_type = GPIO_INTR_DISABLE;
    //set as output mode
    io_conf.mode = mode;
    //bit mask of the pins that you want to set,e.g.GPIO23
    io_conf.pin_bit_mask = BIT64(gpio_num);

    //下拉模式
    if(pullType == INPUT_PULLDOWN)
    {
        io_conf.pull_down_en = 1;
    }
    else io_conf.pull_down_en = 0;

    //上拉模式
    if(pullType == INPUT_PULLUP)
    {
        io_conf.pull_up_en = 1;
    }
    else io_conf.pull_up_en = 0;

    //用给定的设置配置GPIO
    return gpio_config(&io_conf);
}

int device_gpio_set(gpio_num_t gpio_num, int level)
{
    return gpio_set_level(gpio_num, level);
}
